package com.hqyj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.common.ResponseResult;
import com.hqyj.dao.TbEstateManagerMapper;
import com.hqyj.pojo.TbEstateManager;
import com.hqyj.service.TbEstateManagerService;
import com.hqyj.util.EncryptUtil;
import com.hqyj.util.JwtUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 * 物业管理人员表 服务实现类
 * </p>
 *
 * @author gp
 * @since 2021-09-26
 */
@Service
public class TbEstateManagerServiceImpl implements TbEstateManagerService {
    @Autowired
    TbEstateManagerMapper tbEstateManagerMapper;
    @Override
    public HashMap<String, Object> list(TbEstateManager tbEstateManager) {
        HashMap<String,Object> map = new HashMap<>();
        // 第一步：创建分页对象
        Page<TbEstateManager> tbEstateManagerPage = new Page<>(tbEstateManager.getPage(), tbEstateManager.getRow());
        // 创建查询条件对象
        QueryWrapper<TbEstateManager> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(tbEstateManager.getCommunityName() != null && !tbEstateManager.getCommunityName().equals(""),
                "community_name", tbEstateManager.getCommunityName());
        // 第二步：查询分页，获取分页数据集
        Page<TbEstateManager> tbEstateManagerList = tbEstateManagerMapper.selectPage(tbEstateManagerPage, queryWrapper);
        // 获取当前页集合
        map.put("info", tbEstateManagerList.getRecords());
        // 获取总条数
        map.put("total", tbEstateManagerList.getTotal());
        // 获取总页数
        map.put("totalPage", tbEstateManagerList.getPages());
        return map;
    }

    @Override
    public HashMap<String, Object> insert(TbEstateManager tbEstateManager) {
        HashMap<String ,Object> map = new HashMap<>();
        int num = tbEstateManagerMapper.insert(tbEstateManager);
        if (num>0){
            map.put("info","添加成功");
        }else {
            map.put("info","添加失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> update(TbEstateManager tbEstateManager) {
        HashMap<String ,Object> map = new HashMap<>();
        int num = tbEstateManagerMapper.updateById(tbEstateManager);
        if (num>0){
            map.put("info","修改成功");
        }else {
            map.put("info","修改失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> delete(Integer id) {
        HashMap<String ,Object> map = new HashMap<>();
        int num = tbEstateManagerMapper.deleteById(id);
        if (num>0){
            map.put("info","删除成功");
        }else {
            map.put("info","删除失败");
        }
        return map;
    }

    @Override
    public TbEstateManager getByLoginName(String loginName) {
        return tbEstateManagerMapper.getByLoginName(loginName);
    }

    @Override
    public ResponseResult login(String username, String password) {
        HashMap<String, Object> map = new HashMap<>();

        TbEstateManager estateManager1 = tbEstateManagerMapper.login(username, password);
        return null;
    }

    @Override
    public HashMap<String, Object> info(TbEstateManager estateManager) {

        return null;
    }
}
